package com.buddy.learn.javasource._thread;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.Test;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class _Timer {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(1000);
        for (int i=0;i<1000;i++){
            list.add(i);
        }
        list.forEach(integer -> {
            System.out.println("current is i="+integer);
            System.out.println("current time ="+LocalDateTime.now());
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    System.out.println("delay is i = "+integer);
                    System.out.println("delay time= "+LocalDateTime.now());
                }
            },6_000L);
        });
    }

    @Test
    public void dateTest(){
        long timestamp = System.currentTimeMillis();
        System.out.println(timestamp);
        String timestr = DateFormatUtils.format(timestamp,"yyyy-MM-dd HH:mm:ss.S");
        System.out.println(timestr);
    }
}
